package com.twq.patternmatch.pattern.kinds

import com.twq.patternmatch.basic.{BinOp, Number, UnOp, Var}

/**
 * Created by tangweiqun on 2017/12/8.
 */
object Wildcard {
  def main(args: Array[String]): Unit = {
    val expr = BinOp("-", UnOp("-", Var("x")), Number(2))

    //1、通配符模式(Wildcard patterns)
    //1.1、可以用于匹配默认的场景
    expr match {
      case BinOp(op, left, right) =>
        println(expr + " is a binary operation")
      case _ => // handle the default case
    }

    //1.2、可以用于可以忽略的对象的域的情况
    expr match {
      case BinOp(_, _, _) => println(expr + " is a binary operation")
      case _ => println("It's something else")
    }
  }
}
